//
//  Finger.cpp
//  ATM Killer
//
//  Created by USoft on 7/16/14.
//
//

#include "Finger.h"
Finger::Finger() {
    
}

Finger::~Finger(){
    Utils::safeRelease(this->cost);
    Utils::safeRelease(this->dpt);
}

bool Finger::init(){
    this->level = 0;
    this->upgradeLevel = 0;
    this->bonusLevel = 0;
    this->timeToNextUpgrade = 0;
    this->cost = NULL;
    this->dpt = NULL;
    
    this->lastNoti = 0;
    this->hasNoti = false;
    this->upgradeAvailable = false;
    
    this->lastNotiBonus = 0;
    this->hasNotiBonus = false;
    this->bonusAvailable = false;
    return true;
}

void Finger::upLevel(FingerInformation* fingerInformation, int level, int specialLevel, int totalCharactersLevel) {
    BigNumber* newBaseDpt = BigNumber::create();
    newBaseDpt->initialize(0);
    newBaseDpt = this->upgrade(fingerInformation,totalCharactersLevel,specialLevel);
    auto delDpt = this->dpt;
    this->dpt = newBaseDpt->multiplyRationalNumber(level);
    CC_SAFE_RETAIN(this->getDpt());
    Utils::safeRelease(delDpt);
    
    auto delCost = this->cost;
    this->cost = fingerInformation->getBaseCost()->multiplyRationalNumber(pow(1.1,level));
    CC_SAFE_RETAIN(this->cost);
    Utils::safeRelease(delCost);
    this->level = level;
    this->upgradeLevel = specialLevel;
    
}
BigNumber* Finger::upgrade(FingerInformation* fingerInformation, int totalLevel, int specialLevel) {
    BigNumber* newBaseDpt = BigNumber::create();
    newBaseDpt->initialize(1);
    if(specialLevel>=1){
        newBaseDpt = newBaseDpt->add(1);
    }
    if(specialLevel>=2){
        newBaseDpt = newBaseDpt->multiplyAnElement(2);
    }
    if(specialLevel>=3){
        newBaseDpt = newBaseDpt->multiplyAnElement(2);
    }
    if(specialLevel>=4){
        int temp = this->round(totalLevel * 1.0);
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=5){
        int temp = this->round(totalLevel * 5.0);
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=6){
        int temp = this->round(totalLevel * 10.0);
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=7){
        int temp = this->round(totalLevel * 100);
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=8){
        int temp = totalLevel * 500;
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=9){
        int temp = totalLevel * 2000;
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=10){
        int temp = totalLevel * 10000;
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=11){
        int temp = totalLevel * 100000;
        newBaseDpt = newBaseDpt->add(temp);
    }
    if(specialLevel>=12){
        int temp = totalLevel * 1000000;
        newBaseDpt = newBaseDpt->add(temp);
    }
    return newBaseDpt;
}

int Finger::round(float number){
    number = number + 0.5;
    return floor(number);
}
